using System.Collections.Generic;
using System.IO;
using System.Linq;
using EnvDTE;
using Microsoft.VisualStudio.Shell.Interop;

namespace TellagoInc.VsTagExplorer.TagSelector
{
    public class SetTagsWorker : TagsWorker
    {
        public SetTagsWorker(DTE envDte, SVsSolution solution, TagsSelector selector) : base(envDte, solution, selector)
        {
        }

        protected override IEnumerable<string> GetCandidateStrings(IEnumerable<FileItem> selectedItems)
        {
            return selectedItems
                .Select(f => Path.GetFileNameWithoutExtension(f.Name))
                .Select(n => (n.StartsWith("I") ? n.Substring(1) + " Interface" : n))
                .Select(n => n.Select(c => char.IsUpper(c) ? " " + c : c.ToString()).Aggregate((a, b) => a + b).Trim())
                .SelectMany(t => t.Split(' '))
                .Distinct();
        }

        protected override void ApplyTags(string currentTags, string newTags,
                                          IVsBuildPropertyStorage buildPropertyStorage, uint itemId)
        {
            buildPropertyStorage.SetItemAttribute(itemId, "Tags", newTags);
        }
    }
}